package leecode;

import org.junit.Test;

public class Offer40 {

    public int[] getLeastNumbers(int[] arr, int k) {
        if (arr.length == k) {
            return arr;
        }
        int[] vec = new int[k];
        for (int i = 0; i < k; i++) {
            for (int j = i+1; j < arr.length; j++) {
                if (arr[i] > arr[j]) {
                    swap(arr, i, j);
                }
            }
            vec[i] = arr[i];
        }
        return vec;
    }

    public void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    @Test
    public void main(){
        int[] nums = {3, 2, 1};
        System.out.println(getLeastNumbers(nums, 2));
    }


}
